package com.cskaoyan.shopping.converter;

import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.shopping.dal.entitys.Item;
import org.springframework.stereotype.Component;

import javax.annotation.Generated;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Qing
 * @since 2022/06/17 19:41
 */


@Component
public class  ProductDetailConverter {

    public ProductDetailDto item2ProductDto(Item item) {
        if ( item == null ) {
            return null;
        }

        ProductDetailDto productDetailDto = new ProductDetailDto();

        productDetailDto.setProductId( item.getId() );
        productDetailDto.setSubTitle( item.getSellPoint() );
        productDetailDto.setSalePrice( item.getPrice() );
        productDetailDto.setProductImageBig( item.getImageBig() );
        productDetailDto.setProductName( item.getTitle() );
        if ( item.getLimitNum() != null ) {
            productDetailDto.setLimitNum( item.getLimitNum().longValue() );
        }

        String[] images = item.getImages();
        List imageList = new LinkedList();
        for (String image : images) {
            imageList.add(image);
        }
        productDetailDto.setProductImageSmall(imageList);


        return productDetailDto;
    }
}
